import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { NotificationInformationDTO } from 'src/app/project/model/icm/icm-student-academic/notification-information/notification-information.dto';
import { Observable } from 'rxjs';
import { ApiPagedData } from 'src/app/project/model/common/api-paged-data';
import { QueryOptions } from 'src/app/project/model/common/query-options';

@Injectable({
  providedIn: 'root',
})
export class NotificationInformationService {
  private static URL = '/api/icm-notification-information';

  constructor(private http: _HttpClient) {}

  /**
   * 分页查询通知信息
   * @param option 分页参数
   * @param title  通知标题
   * @param type  通知类型
   * @param receiverName  通知对象
   */
  findOnePage(
    option: QueryOptions,
    title?: string,
    type?: string,
    receiverName?: string,
  ): Observable<ApiPagedData<NotificationInformationDTO>> {
    const params = {};
    Object.assign(params, option, title ? { title } : {}, type ? { type } : {}, receiverName ? { receiverName } : {});
    return this.http.get<ApiPagedData<NotificationInformationDTO>>(NotificationInformationService.URL, params);
  }

  /**
   * 添加通知
   * @param notificationInformationDTO  通知信息
   */
  create(notificationInformationDTO: NotificationInformationDTO): Observable<NotificationInformationDTO> {
    return this.http.post<NotificationInformationDTO>(NotificationInformationService.URL, notificationInformationDTO);
  }

  /**
   * 根据id查找通知
   * @param id 通知id
   */
  findById(id: string): Observable<NotificationInformationDTO> {
    return this.http.get<NotificationInformationDTO>(`${NotificationInformationService.URL}/${id}`);
  }

  /**
   * 根据接收者id查找通知
   * @param id 通知id
   */
  findByReceiverId(id: string): Observable<Array<NotificationInformationDTO>> {
    return this.http.get<Array<NotificationInformationDTO>>(`${NotificationInformationService.URL}/receiver/${id}`);
  }

  /**
   * 改变通知状态
   * @param id 通知id
   */
  complete(id: string): Observable<NotificationInformationDTO> {
    return this.http.put<NotificationInformationDTO>(`${NotificationInformationService.URL}/change-status/${id}`);
  }

  /**
   * 根据id删除通知
   * @param id 通知id
   */
  delete(id: string): Observable<NotificationInformationDTO> {
    return this.http.delete<NotificationInformationDTO>(`${NotificationInformationService.URL}/${id}`);
  }
}
